/// 注册请求模型
class RegisterRequest {
  /// 用户名
  final String username;
  
  /// 电子邮箱
  final String email;
  
  /// 密码
  final String password;
  
  /// 确认密码
  final String confirmPassword;
  
  /// 姓名
  final String? fullName;
  
  /// 手机号
  final String? phone;
  
  /// 接受条款
  final bool acceptTerms;
  
  /// 构造函数
  RegisterRequest({
    required this.username,
    required this.email,
    required this.password,
    required this.confirmPassword,
    this.fullName,
    this.phone,
    this.acceptTerms = false,
  });
  
  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'username': username,
      'email': email,
      'password': password,
      'confirm_password': confirmPassword,
      if (fullName != null) 'full_name': fullName,
      if (phone != null) 'phone': phone,
      'accept_terms': acceptTerms,
    };
  }
  
  /// 验证请求数据
  bool isValid() {
    // 验证必填字段
    if (username.isEmpty || email.isEmpty || password.isEmpty || confirmPassword.isEmpty) {
      return false;
    }
    
    // 验证密码一致性
    if (password != confirmPassword) {
      return false;
    }
    
    // 验证密码长度
    if (password.length < 8) {
      return false;
    }
    
    // 验证邮箱格式
    final emailRegExp = RegExp(r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+');
    if (!emailRegExp.hasMatch(email)) {
      return false;
    }
    
    // 验证条款
    if (!acceptTerms) {
      return false;
    }
    
    return true;
  }
  
  /// 创建一个新的注册请求，复制原有属性并覆盖指定属性
  RegisterRequest copyWith({
    String? username,
    String? email,
    String? password,
    String? confirmPassword,
    String? fullName,
    String? phone,
    bool? acceptTerms,
  }) {
    return RegisterRequest(
      username: username ?? this.username,
      email: email ?? this.email,
      password: password ?? this.password,
      confirmPassword: confirmPassword ?? this.confirmPassword,
      fullName: fullName ?? this.fullName,
      phone: phone ?? this.phone,
      acceptTerms: acceptTerms ?? this.acceptTerms,
    );
  }
} 